package com.hdd.biz.painting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdd.biz.painting.entity.Favour;
import com.hdd.biz.painting.entity.PaintingWorks;
import com.hdd.biz.painting.mapper.FavourMapper;
import com.hdd.biz.painting.service.FavourService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 收藏喜欢表 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-03-16
 */
@Service
public class FavourServiceImpl extends ServiceImpl<FavourMapper, Favour> implements FavourService {

    @Override
    public int insertFavour(String userId, String paintingId) {
        Favour favour = new Favour();
        favour.setDelFlag(0);
        favour.setUserId(userId);
        favour.setPaintingId(paintingId);
        return baseMapper.insert(favour);
    }


    @Override
    public boolean delFavour(String userId, String paintingId) {
        QueryWrapper<Favour> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("painting_id",paintingId);
        return baseMapper.delete(queryWrapper)>0?true:false;
    }

    @Override
    public boolean isFavour(String userId, String paintingId) {
        QueryWrapper<Favour> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("painting_id",paintingId);
        return baseMapper.selectCount(queryWrapper)>0;
    }

    @Override
    public int favours(String userId) {
        QueryWrapper<Favour> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        return baseMapper.selectCount(queryWrapper);
    }

    @Override
    public int totalFavour() {
        QueryWrapper<Favour> wrapper = new QueryWrapper();
        return baseMapper.selectCount(wrapper);
    }

    @Override
    public int todayFavour() {
        QueryWrapper<Favour> wrapper = new QueryWrapper();
        wrapper.last("WHERE TO_DAYS(create_time) = TO_DAYS(NOW())");
        return baseMapper.selectCount(wrapper);
    }
}
